﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Build.Framework;

namespace XNACompilator
{
    /// <summary>
    /// Logger use for get any error when the compilation
    /// </summary>
    public class ErrorLogger :ILogger
    {
        #region Field

        private string m_parma;
        private List<string> m_log;
        private LoggerVerbosity m_verbo;
        private IEventSource m_eventsource;
        
        #endregion

        #region CTOR

        /// <summary>
        /// Constructor
        /// </summary>
        public ErrorLogger()
        {
            m_log = new List<string>();
        }
        
        #endregion

        #region Method

        /// <summary>
        /// Initialize method from ILogger interface
        /// </summary>
        /// <param name="eventSource">Interface giving access to events raised during the compilation </param>
        public void Initialize(IEventSource eventSource)
        {
            if (eventSource != null)
            {
                eventSource.ErrorRaised += new BuildErrorEventHandler(eventSource_ErrorRaised);
                m_eventsource = eventSource;
            }
        }

        /// <summary>
        /// Handler of error found into the compilation
        /// </summary>
        /// <param name="sender">sender</param>
        /// <param name="e">Error information</param>
        private void eventSource_ErrorRaised(object sender, BuildErrorEventArgs e)
        {
            this.m_log.Add(e.Message);
        }

        /// <summary>
        /// Method empty but necessaries into ILogger
        /// </summary>
        public void Shutdown()
        {
        }


        #endregion

        #region Property

        /// <summary>
        /// Parameters use into ILogger
        /// </summary>
        public string Parameters
        {
            get { return this.m_parma; }
            set {this.m_parma = value;}
        }

        /// <summary>
        /// ILogger Verbosity
        /// </summary>
        public LoggerVerbosity Verbosity
        {
            get { return this.m_verbo; }
            set { this.m_verbo = value; }
        }

        /// <summary>
        /// Error list use for create the error's message
        /// </summary>
        internal List<String> Errors
        {
            get { return this.m_log; }
        }
        #endregion
    }
}
